<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>  
<%@ taglib prefix="ujn" uri="http://ujn.edu.cn/common/"%> 
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() 
	                   + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML> 
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>产品管理</title>
	<!-- 引入css样式文件1 -->
	<!-- Bootstrap Core CSS -->
	<link href="<%=basePath%>css/bootstrap.min.css" rel="stylesheet" />
	<!-- MetisMenu CSS -->
	<link href="<%=basePath%>css/metisMenu.min.css" rel="stylesheet" />
	<!-- DataTables CSS -->
	<link href="<%=basePath%>css/dataTables.bootstrap.css" rel="stylesheet" />
	<!-- Custom CSS -->
	<link href="<%=basePath%>css/sb-admin-2.css" rel="stylesheet" />
	<!-- Custom Fonts -->
	<link href="<%=basePath%>css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<link href="<%=basePath%>css/boot-crm.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
  <!-- 导航栏部分 -->
  <nav class="navbar navbar-default navbar-static-top" role="navigation"
		 style="margin-bottom: 0">
	<div class="navbar-header">
		<a class="navbar-brand" href="<%=basePath%>customer/list.action">客户管理系统</a>
	</div>
	<!-- 导航栏右侧图标部分 -->
	<ul class="nav navbar-top-links navbar-right">
		<li class="dropdown">
			<a class="dropdown-toggle" data-toggle="dropdown" href="#"> 系统设置
			</a>
			<ul class="dropdown-menu dropdown-user">
				<li>
					<a href="${pageContext.request.contextPath }/logout.action">
					退出登录
					</a>
				</li>
			</ul> 
		</li>
	</ul>
	<!-- 左侧显示列表部分 start-->
	<div class="navbar-default sidebar" role="navigation">
		<div class="sidebar-nav navbar-collapse">
			<ul class="nav" id="side-menu">
				
				<li>
				    <a href="${pageContext.request.contextPath }/customer/list.action" class="active">
				      客户管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/user/list.action" class="active">
				      用户管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/product/list.action" class="active">
				      产品管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/orders/list.action" class="active">
				      订单管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/project/list.action" class="active">
				      进货管理
				    </a>
				</li>
				<li>
				    <a href="${pageContext.request.contextPath }/basedict/list.action" class="active">
				      数据字典管理
				    </a>
				</li>
			</ul>
		</div>
	</div>
	<!-- 左侧显示列表部分 end--> 
  </nav>
  		<!-- 产品列表查询部分  start-->
		<div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
					<h1 class="page-header">产品管理</h1>
				</div>
				<!-- /.col-lg-12 -->
			</div>
			<!-- /.row -->
			<div class="panel panel-default">
				<div class="panel-body">
					<form class="form-inline" method="get"
						action="${pageContext.request.contextPath }/product/list.action">
						<div class="form-group">
							<label for="productid">产品编号</label> 
							<input type="text" class="form-control" id="id" value="${id }"
								name="id" />
						</div>
						<div class="form-group">
							<label for="productName">产品名称</label> 						
							<input type="text" class="form-control" id="name" 
						                   value="${name}" name="name" />
						</div>
						<div class="form-group">
						<label for="productprice">产品价格</label> 
						<input type="text" class="form-control" id="price" 
						                   value="${price}" name="price" />
					</div>
						<button type="submit" class="btn btn-primary">查询</button>
					</form>
				</div>
			</div>
			
			
			<a href="#" class="btn btn-primary" data-toggle="modal"
				data-target="#newproductDialog" onclick="clearProduct()">新建</a>
			<div class="row">
				<div class="col-lg-12">
					<div class="panel panel-default">
						<div class="panel-heading">产品信息列表</div>
						<!-- /.panel-heading -->
						<table class="table table-bordered table-striped">
							<thead>
								<tr>
									<th>编号</th>
									<th>产品名称</th>
									<th>产品价格</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody>
								<c:forEach items="${page.rows}" var="row">
									<tr>
										<td>${row.id}</td>
										<td>${row.name}</td>
										<td>${row.price}</td>
										<td>
											<a href="#" class="btn btn-primary btn-xs"
											data-toggle="modal" data-target="#productEditDialog"
											onclick="editProduct(${row.id})">修改</a> <a href="#"
											class="btn btn-danger btn-xs"
											onclick="deleteProduct(${row.id})">删除</a></td>
										</td>
									</tr>
								</c:forEach>
							</tbody>
						</table>
						<div class="col-md-12 text-right">
							<ujn:page
								url="${pageContext.request.contextPath }/product/list.action" />
						</div>
						<!-- /.panel-body -->
					</div>
					<!-- /.panel -->
				</div>
				<!-- /.col-lg-12 -->
			</div>
		</div>
<!-- 产品列表查询部分  end-->
	<!-- 创建产品模态框 -->
	<div class="modal fade" id="newproductDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">新建产品信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="new_product_form">
						<div class="form-group">
							<label for="new_productname" class="col-sm-2 control-label">
								产品名称 </label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="new_productname"
									placeholder="产品名称" name="name" />
							</div>
						</div>
						<div class="form-group">
							<label for="new_productprice" class="col-sm-2 control-label">
								产品价格 </label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="new_productprice"
									placeholder="产品价格" name="price" />
							</div>
						</div>
					
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="createProduct()">创建产品</button>
				</div>
			</div>
		</div>
	</div>
	
	<!-- 修改产品模态框 -->
	<div class="modal fade" id="productEditDialog" tabindex="-1"
		role="dialog" aria-labelledby="myModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel">修改客户信息</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="edit_product_form">
					<input type="hidden" class="form-control" id="edit_productId" placeholder="产品编号" name="id" />
						<div class="form-group">
							<label for="edit_productName" class="col-sm-2 control-label">产品名称</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_productName"
									placeholder="产品名称" name="name" />
							</div>
						</div>
						<div class="form-group">
							<label for="edit_productPrice" class="col-sm-2 control-label">产品价格</label>
							<div class="col-sm-10">
								<input type="text" class="form-control" id="edit_productPrice"
									placeholder="产品价格" name="price" />
							</div>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary"
						onclick="updateProduct()">保存修改</button>
				</div>
			</div>
		</div>
	</div>
		<!-- 引入js文件 -->
	<!-- jQuery -->
	<script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
	<!-- Bootstrap Core JavaScript -->
	<script src="<%=basePath%>js/bootstrap.min.js"></script>
	<!-- Metis Menu Plugin JavaScript -->
	<script src="<%=basePath%>js/metisMenu.min.js"></script>
	<!-- DataTables JavaScript -->
	<script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
	<script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>
	<!-- Custom Theme JavaScript -->
	<script src="<%=basePath%>js/sb-admin-2.js"></script>
	<!-- 编写js代码 -->
	<script type="text/javascript">
	//清空新建订单中的数据
	function clearProduct() {
	    $("#new_productid").val("");
	    $("#new_productname").val("");
	    $("#new_productprice").val("");
	}
	// 创建产品
	function createProduct() {
	$.post("<%=basePath%>product/create.action",
	$("#new_product_form").serialize(), 
	function(data){
	        if(data =="OK"){
	            alert("产品创建成功！");
	            window.location.reload();
	        }else{
	            alert("产品创建失败！");
	            window.location.reload();
	        }
	    });
	}
	// 通过id获取修改的产品信息
	function editProduct(id) {
	    $.ajax({
	        type:"get",
	        url:"<%=basePath%>product/getProductById.action",
	        data:{"id":id},
	        success:function(data) {
	            $("#edit_productId").val(data.id);
	            $("#edit_productName").val(data.name);
	            $("#edit_productPrice").val(data.price);
	        }
	    });
	}
	 // 执行修改产品操作
	function updateProduct() {
		$.post("<%=basePath%>product/update.action",
		$("#edit_product_form").serialize(),function(data){
			if(data =="OK"){
				alert("产品信息更新成功！");
				window.location.reload();
			}else{
				alert("产品信息更新失败！");
				window.location.reload();
			}
			
		});
	}
	// 删除客户
	function deleteProduct(id) {
	    if(confirm('确实要删除该客户吗?')) {
	$.post("<%=basePath%>product/delete.action",{"id":id},
	function(data){
	            if(data =="OK"){
	                alert("产品删除成功！");
	                window.location.reload();
	            }else{
	                alert("删除产品失败！");
	                window.location.reload();
	            }
	        });
	    }
	}
</script>
</body>
</html>
	

		
  